Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BudgetEditorComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor", description: "", icon: "WBData/ComponentEditorProps/componentEditor.png")]
5
6void ScriptInvoker_EntityBudgetMaxUpdated(EEditableEntityBudget budgetType, int currentBudgetValue, int newMaxBudgetValue);
8typedef ScriptInvokerBase<ScriptInvoker_EntityBudgetMaxUpdated> ScriptInvoker_EntityBudgetMaxUpdatedEvent;
9
10void ScriptInvoker_EntityBudgetUpdated(EEditableEntityBudget budgetType, int originalBudgetValue, int updatedBudgetValue, int maxBudgetValue);
12typedef ScriptInvokerBase<ScriptInvoker_EntityBudgetUpdated> ScriptInvoker_EntityBudgetUpdatedEvent;
13
16typedef ScriptInvokerBase<ScriptInvoker_EntityBudgetMaxReached> ScriptInvoker_EntityBudgetMaxReachedEvent;
17
18// if enabled we will perform double checks to make sure nothing broke
19#define BUDGET_OPTIMIZATION_CHECKS
20
22{
23 const int DEFAULT_MAX_BUDGET = 100;
24 const int DEFAULT_MIN_COST = 1;
25
26 [Attribute(desc: "Define maximum budget values for player")]
27 protected ref array<ref SCR_EntityBudgetValue> m_MaxBudgets;
28
29 //contains all the budgets, even those not defined as an attribute
31
34
36
42
43 //Delayed set max values
45 protected bool m_bListenToMaxBudgetDelay = false;
46
47 //------------------------------------------------------------------------------------------------
53 bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out EEditableEntityBudget blockingBudget, bool showNotification)
54 {
55 array<ref SCR_EntityBudgetValue> budgetCosts = {};
56 return CanPlaceEntityInfo(info, budgetCosts, blockingBudget, showNotification);
57 }
58
59 //------------------------------------------------------------------------------------------------
66 bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget, bool showNotification)
67 {
68 if (!IsBudgetCapEnabled())
69 return true;
70
71 bool canPlace = false;
72 if (GetEntityPreviewBudgetCosts(info, budgetCosts))
73 canPlace = CanPlace(budgetCosts, blockingBudget);
74 else
75 canPlace = CanPlaceEntityType(info.GetEntityType(), budgetCosts, blockingBudget);
76
77 if (showNotification)
78 CanPlaceResult(canPlace, showNotification);
79
80 return canPlace;
81 }
82
83 //------------------------------------------------------------------------------------------------
91 bool CanPlaceEntitySource(IEntityComponentSource editableEntitySource, out EEditableEntityBudget blockingBudget, bool isPlacingPlayer = false, bool updatePreview = true, bool showNotification = true)
92 {
93 bool canPlace = true;
94 if (editableEntitySource && IsBudgetCapEnabled())
95 {
96 array<ref SCR_EntityBudgetValue> budgetCosts = {};
97 if (!GetEntitySourcePreviewBudgetCosts(editableEntitySource, budgetCosts))
98 {
99 canPlace = false;
100 }
101 // Clear budget cost when placing as player
102 if (isPlacingPlayer)
103 budgetCosts.Clear();
104
105 if (updatePreview)
106 UpdatePreviewCost(budgetCosts);
107
108 canPlace = canPlace && CanPlace(budgetCosts, blockingBudget);
109 }
110 return CanPlaceResult(canPlace, showNotification);
111 }
112
113 void GetBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
114 {
115 GetEntitySourcePreviewBudgetCosts(editableEntitySource, budgetCosts);
116 }
117
118 void GetBudgetCostsDontDiscardCampaignBudget(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
119 {
120 if (!editableEntitySource)
121 return;
122
123 SCR_EditableEntityUIInfo editableUIInfo = SCR_EditableEntityComponentClass.GetInfo(editableEntitySource);
124 if (editableUIInfo)
125 GetEntityPreviewBudgetCostsDontDiscardCampaignBudget(editableUIInfo, budgetCosts);
126
127 return;
128 }
129
130 //------------------------------------------------------------------------------------------------
136 protected bool CanPlaceEntityType(EEditableEntityType entityType, out notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget)
137 {
138 if (!IsBudgetCapEnabled())
139 return true;
140
141 GetEntityTypeBudgetCost(entityType, budgetCosts);
142 return CanPlace(budgetCosts, blockingBudget);
143 }
144
145 //------------------------------------------------------------------------------------------------
150 bool CanPlace(notnull array<ref SCR_EntityBudgetValue> budgetCosts, out EEditableEntityBudget blockingBudget)
151 {
152 if (!IsBudgetCapEnabled() || budgetCosts.IsEmpty())
153 return true;
154
155 foreach (SCR_EntityBudgetValue budgetCost : budgetCosts)
156 {
157 if (!CanPlace(budgetCost, blockingBudget))
158 return false;
159 }
160 return true;
161 }
162
163 //------------------------------------------------------------------------------------------------
164 protected bool CanPlace(SCR_EntityBudgetValue budgetCost, out EEditableEntityBudget blockingBudget)
165 {
166 EEditableEntityBudget budgetType = budgetCost.GetBudgetType();
167 int maxBudgetValue;
168 if (!GetMaxBudgetValue(budgetType, maxBudgetValue))
169 return false;
170
171 int originalBudgetValue = GetCurrentBudgetValue(budgetType);
172 int budgetChange = budgetCost.GetBudgetValue();
173 if (!CanPlace(originalBudgetValue, budgetChange, maxBudgetValue))
174 {
175 blockingBudget = budgetType;
176 return false;
177 }
178 else
179 {
180 return true;
181 }
182 }
183
184 //------------------------------------------------------------------------------------------------
185 protected bool CanPlace(int currentBudget, int budgetChange, int maxBudget)
186 {
187 return currentBudget + budgetChange <= maxBudget;
188 }
189
190 //------------------------------------------------------------------------------------------------
194 bool GetEntityPreviewBudgetCosts(SCR_EditableEntityUIInfo entityUIInfo, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
195 {
196 if (!entityUIInfo)
197 return false;
198
199 if (!entityUIInfo.GetEntityBudgetCost(budgetCosts))
200 GetEntityTypeBudgetCost(entityUIInfo.GetEntityType(), budgetCosts);
201
202 array<ref SCR_EntityBudgetValue> entityChildrenBudgetCosts = {};
203 entityUIInfo.GetEntityChildrenBudgetCost(entityChildrenBudgetCosts);
204
205 SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, entityChildrenBudgetCosts);
206
207 FilterAvailableBudgets(budgetCosts);
208
209 return true;
210 }
211
212 //------------------------------------------------------------------------------------------------
216 bool GetEntityPreviewBudgetCostsDontDiscardCampaignBudget(SCR_EditableEntityUIInfo entityUIInfo, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
217 {
218 if (!entityUIInfo)
219 return false;
220
221 if (!entityUIInfo.GetEntityBudgetCost(budgetCosts))
222 GetEntityTypeBudgetCost(entityUIInfo.GetEntityType(), budgetCosts);
223
224 array<ref SCR_EntityBudgetValue> entityChildrenBudgetCosts = {};
225 entityUIInfo.GetEntityChildrenBudgetCost(entityChildrenBudgetCosts);
226
227 SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, entityChildrenBudgetCosts);
228
230
231 return true;
232 }
233
234 //------------------------------------------------------------------------------------------------
238 bool GetEntitySourcePreviewBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
239 {
240 if (!editableEntitySource)
241 return false;
242
243 SCR_EditableEntityUIInfo editableUIInfo = SCR_EditableEntityComponentClass.GetInfo(editableEntitySource);
244 if (editableUIInfo)
245 return GetEntityPreviewBudgetCosts(editableUIInfo, budgetCosts);
246
247 return false;
248 }
249
250 //------------------------------------------------------------------------------------------------
257 bool GetVehicleOccupiedBudgetCosts(IEntityComponentSource editableEntitySource, EEditorPlacingFlags placingFlags, out notnull array<ref SCR_EntityBudgetValue> budgetCosts, bool includeVehicleCost = true)
258 {
259 if (includeVehicleCost && !GetEntitySourcePreviewBudgetCosts(editableEntitySource, budgetCosts))
260 return false;
261
263 return GetVehicleOccupiedBudgetCosts(editableUIInfo, placingFlags, budgetCosts);
264 }
265
266 //------------------------------------------------------------------------------------------------
271 bool GetVehicleOccupiedBudgetCosts(SCR_EditableVehicleUIInfo editableUIInfo, EEditorPlacingFlags placingFlags, out notnull array<ref SCR_EntityBudgetValue> budgetCosts)
272 {
273 if (!editableUIInfo)
274 return false;
275
276 array<ref SCR_EntityBudgetValue> vehicleOccupantsBudgetCosts = {};
277
278 if (placingFlags & EEditorPlacingFlags.VEHICLE_CREWED)
279 {
280 editableUIInfo.GetFillBudgetCostsOfCrew(vehicleOccupantsBudgetCosts);
281 SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, vehicleOccupantsBudgetCosts);
282 }
283
284 if (placingFlags & EEditorPlacingFlags.VEHICLE_PASSENGER)
285 {
286 editableUIInfo.GetFillBudgetCostsOfPassengers(vehicleOccupantsBudgetCosts);
287 SCR_EntityBudgetValue.MergeBudgetCosts(budgetCosts, vehicleOccupantsBudgetCosts);
288 }
289
290 return true;
291 }
292
293 //------------------------------------------------------------------------------------------------
296 void UpdatePreviewCost(notnull array<ref SCR_EntityBudgetValue> budgetCosts)
297 {
299 foreach (SCR_EntityBudgetValue budgetCost : budgetCosts)
300 {
301 EEditableEntityBudget budgetType = budgetCost.GetBudgetType();
302 int budgetValue = budgetCost.GetBudgetValue();
303 int maxBudget;
304 if (!GetMaxBudgetValue(budgetType, maxBudget))
305 continue;
306
307 float max = maxBudget;
308 // Calculate current budget percentage
309 int currentBudget = GetCurrentBudgetValue(budgetType);
310 float newBudgetPercent;
311 float budgetChange;
312 if (max != 0)
313 {
314 // Calculate budget percentage after entity is placed
315 float currentBudgetPercent = currentBudget / max * 100;
316 int newBudget = currentBudget + budgetValue;
317
318 newBudgetPercent = newBudget / max * 100;
319 // How much the budget percentage is increased
320 budgetChange = newBudgetPercent - currentBudgetPercent;
321 }
322 else
323 {
324 newBudgetPercent = 100;
325 budgetChange = 0; // Show no change when maxbudget is 0
326 }
327
328 Event_OnBudgetPreviewUpdated.Invoke(budgetType, newBudgetPercent, budgetChange);
329 }
330 }
331
332 //------------------------------------------------------------------------------------------------
335 {
337 }
338
339 //------------------------------------------------------------------------------------------------
341 {
343 return GetMaxBudget(type, budget);
344 }
345
346 //------------------------------------------------------------------------------------------------
348 {
349 #ifdef BUDGET_OPTIMIZATION_CHECKS
350 const bool result = m_maxBudgetsInternal.Find(type, budget);
351
352 if(result && !budget)
353 {
354 Print("GetMaxBudget: Budget type wasn't defined!", LogLevel.ERROR);
355 return GetMaxBudget_Old(type, budget);
356 }
357 #endif
358
359 return m_maxBudgetsInternal.Find(type, budget);
360 }
361
362
363 //old version of GetMaxBudget
364 //------------------------------------------------------------------------------------------------
366 {
367 //iterate like we used to do
368 foreach (SCR_EntityBudgetValue maxBudget : m_MaxBudgets)
369 {
370 if(!maxBudget)
371 continue;
372
373 if (maxBudget.GetBudgetType() == type)
374 {
375 budget = maxBudget;
376 return true;
377 }
378 }
379 return false;
380 }
381
382 //------------------------------------------------------------------------------------------------
388 {
389 SCR_EntityBudgetValue budgetValue;
390 if (GetMaxBudget(type, budgetValue))
391 {
392 maxBudget = budgetValue.GetBudgetValue();
393 return true;
394 }
395 return false;
396 }
397
398 //------------------------------------------------------------------------------------------------
403 {
404 int oldValue = 0;
405 SCR_EntityBudgetValue maxBudget;
406 if (GetMaxBudget(type, maxBudget))
407 {
408 oldValue = maxBudget.GetBudgetValue();
409 maxBudget.SetBudgetValue(newValue);
410 }
411 Rpc(UpdateMaxBudgetOwner, type, oldValue, newValue);
412 }
413
414 //------------------------------------------------------------------------------------------------
419 void DelayedSetMaxBudgetSetup(EEditableEntityBudget type, int newValue, int playerChangingBudget)
420 {
421 m_DelayedSetMaxBudgetsMap.Insert(type, newValue);
422
424 {
426 GetGame().GetCallqueue().CallLater(DelayedSetMaxBudget, 100, false, playerChangingBudget);
427 }
428 }
429
430 //------------------------------------------------------------------------------------------------
431 protected void DelayedSetMaxBudget(int playerChangingBudget)
432 {
436 }
437
438 //------------------------------------------------------------------------------------------------
441 void SetMultiMaxBudgetValues(notnull map<EEditableEntityBudget, int> budgets, int playerChangingBudget)
442 {
443 foreach (EEditableEntityBudget type, int budget: budgets)
444 {
445 SetMaxBudgetValue(type, budget);
446 }
447 }
448
449 //------------------------------------------------------------------------------------------------
453 void GetEntityTypeBudgetCost(EEditableEntityType entityType, out array<ref SCR_EntityBudgetValue> budgetCosts)
454 {
455 EEditableEntityBudget entityBudgetType = m_EntityCore.GetBudgetForEntityType(entityType);
456 int minBudgetCost = GetEntityTypeBudgetCost(entityBudgetType);
457
458 budgetCosts = { new SCR_EntityBudgetValue(entityBudgetType, minBudgetCost) };
459 }
460
461 //------------------------------------------------------------------------------------------------
463 {
464 SCR_EditableEntityCoreBudgetSetting budgetSettings = m_BudgetSettingsMap.Get(budgetType);
465 if (budgetSettings)
466 return budgetSettings.GetMinBudgetCost();
467
468 return DEFAULT_MIN_COST;
469 }
470
471 //------------------------------------------------------------------------------------------------
476 {
477 SCR_EditableEntityCoreBudgetSetting budgetSettings;
478 if (!GetCurrentBudgetSettings(type, budgetSettings))
479 return 0;
480
481 return budgetSettings.GetCurrentBudget() + budgetSettings.GetReservedBudget();
482 }
483
484 //------------------------------------------------------------------------------------------------
489 {
490 int originalBudgetValue, budgetChange, maxBudgetValue;
491 SCR_EditableEntityCoreBudgetSetting budgetSettings;
492 if (GetCurrentBudgetSettings(budgetType, budgetSettings) && GetMaxBudgetValue(budgetType, maxBudgetValue))
493 {
494 originalBudgetValue = budgetSettings.GetCurrentBudget();
495 budgetChange = budgetSettings.SetCurrentBudget(value);
496
497 if (budgetChange != value - originalBudgetValue)
498 budgetChange = 0;
499
500 bool budgetMaxReached;
501 bool sendBudgetMaxEvent = CheckMaxBudgetReached(budgetType, budgetChange, originalBudgetValue, value, maxBudgetValue, budgetMaxReached);
502
503 Rpc(OnEntityCoreBudgetUpdatedOwner, budgetType, value, budgetChange, sendBudgetMaxEvent, budgetMaxReached);
504 }
505 }
506
507 //------------------------------------------------------------------------------------------------
512 bool GetCurrentBudgetInfo(EEditableEntityBudget budgetType, out SCR_UIInfo blockingBudgetInfo)
513 {
514 SCR_EditableEntityCoreBudgetSetting budgetSettings;
515 if (GetCurrentBudgetSettings(budgetType, budgetSettings))
516 {
517 blockingBudgetInfo = budgetSettings.GetInfo();
518 return true;
519 }
520 return false;
521 }
522
523 //------------------------------------------------------------------------------------------------
525 void GetBudgets(out notnull array<ref SCR_EditableEntityCoreBudgetSetting> budgets)
526 {
527 foreach (EEditableEntityBudget budgetType, SCR_EditableEntityCoreBudgetSetting setting : m_BudgetSettingsMap)
528 {
529 budgets.Insert(setting);
530 }
531 }
532
533 //------------------------------------------------------------------------------------------------
534 protected bool GetCurrentBudgetSettings(EEditableEntityBudget budgetType, out SCR_EditableEntityCoreBudgetSetting budgetSettings)
535 {
536 return m_BudgetSettingsMap.Find(budgetType, budgetSettings);
537 }
538
539 //------------------------------------------------------------------------------------------------
541 protected void RefreshBudgetSettings()
542 {
544
545 if (!m_EntityCore)
546 return;
547
548 array<ref SCR_EditableEntityCoreBudgetSetting> outBudgets = {};
549 m_EntityCore.GetBudgets(outBudgets);
550
551 SCR_EditableEntityCoreBudgetSetting budget;
552 for (int i = outBudgets.Count() - 1; i >= 0; i--)
553 {
554 budget = outBudgets[i];
555 EEditableEntityBudget budgetType = budget.GetBudgetType();
556 int maxBudget;
557 if (GetMaxBudgetValue(budgetType, maxBudget))
558 {
559 m_BudgetSettingsMap.Insert(budgetType, budget);
560 int currentBudgetValue = budget.GetCurrentBudget();
561 Event_OnBudgetUpdated.Invoke(budgetType, currentBudgetValue, currentBudgetValue, maxBudget);
562 Event_OnBudgetMaxUpdated.Invoke(budgetType, currentBudgetValue, maxBudget);
563 }
564 else
565 {
566 outBudgets.RemoveOrdered(i);
567 }
568 }
569 }
570
571 //------------------------------------------------------------------------------------------------
572 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
573 protected void UpdateMaxBudgetOwner(int budgetType, int oldMaxBudget, int newMaxBudget)
574 {
575 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES))
576 Print(string.Format("Updated maximum budget received for type %1: %2", budgetType, newMaxBudget), LogLevel.NORMAL);
577
578 SCR_EntityBudgetValue maxBudget;
579 if (GetMaxBudget(budgetType, maxBudget))
580 maxBudget.SetBudgetValue(newMaxBudget);
581
582 int currentBudget = GetCurrentBudgetValue(budgetType);
583 // Notify max budget reached
584 if (oldMaxBudget == 0 || (currentBudget > oldMaxBudget && currentBudget < newMaxBudget)) // current budget above old budget, below new max budget
585 Event_OnBudgetMaxReached.Invoke(budgetType, false);
586 else if (newMaxBudget == 0 || (currentBudget < oldMaxBudget && currentBudget > newMaxBudget)) // current budget below old budget, above new max budget
587 Event_OnBudgetMaxReached.Invoke(budgetType, true);
588
589 Event_OnBudgetMaxUpdated.Invoke(budgetType, currentBudget, newMaxBudget);
590 }
591
592 //------------------------------------------------------------------------------------------------
593 protected bool CanPlaceResult(bool canPlace, bool showNotification)
594 {
595 if (showNotification)
596 Rpc(CanPlaceOwner, canPlace);
597
598 return canPlace;
599 }
600
601 //------------------------------------------------------------------------------------------------
602 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
603 protected void CanPlaceOwner(bool canPlace)
604 {
605 if (!canPlace)
606 {
607 GetManager().SendNotification(ENotification.EDITOR_PLACING_BUDGET_MAX);
608 //Event_OnBudgetMaxReached.Invoke(budgetType, maxBudgetReached);
609 }
610 }
611
612 //------------------------------------------------------------------------------------------------
613 protected void OnEntityCoreBudgetUpdated(EEditableEntityBudget entityBudget, int originalBudgetValue, int budgetChange, int updatedBudgetValue)
614 {
615 IEntity owner = GetOwner();
616 if (!owner || owner.IsDeleted())
617 return;
618
619 int maxBudgetValue;
620 if (!GetMaxBudgetValue(entityBudget, maxBudgetValue))
621 return;
622
623 bool budgetMaxReached;
624 bool sendBudgetMaxEvent = CheckMaxBudgetReached(entityBudget, budgetChange, originalBudgetValue, updatedBudgetValue, maxBudgetValue, budgetMaxReached);
625 /*if (!IsOwner())*/
626 Rpc(OnEntityCoreBudgetUpdatedOwner, entityBudget, updatedBudgetValue, budgetChange, sendBudgetMaxEvent, budgetMaxReached);
627 }
628
629 //------------------------------------------------------------------------------------------------
630 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
631 protected void OnEntityCoreBudgetUpdatedOwner(EEditableEntityBudget entityBudget, int budgetValue, int budgetChange, bool sendBudgetMaxEvent, bool budgetMaxReached)
632 {
633 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES))
634 Print(string.Format("Updated budget received for type %1: %2", entityBudget, budgetValue), LogLevel.NORMAL);
635
636 int maxBudget;
637 SCR_EditableEntityCoreBudgetSetting budgetSettings;
638 if (GetCurrentBudgetSettings(entityBudget, budgetSettings) && GetMaxBudgetValue(entityBudget, maxBudget))
639 {
640 int currentBudget = budgetSettings.GetCurrentBudget();
641 int ownerBudgetChange = budgetSettings.SetCurrentBudget(budgetValue);
642
643 Event_OnBudgetUpdated.Invoke(entityBudget, currentBudget, budgetValue, maxBudget);
644
645 if (sendBudgetMaxEvent)
646 Event_OnBudgetMaxReached.Invoke(entityBudget, budgetMaxReached);
647 }
648 }
649
650 //------------------------------------------------------------------------------------------------
651 protected bool CheckMaxBudgetReached(EEditableEntityBudget entityBudget, int budgetChange, int originalBudgetValue, int updatedBudgetValue, int maxBudgetValue, out bool maxBudgetReached)
652 {
653 if (budgetChange >= 0 && originalBudgetValue + budgetChange >= maxBudgetValue)
654 {
655 // Send budget max reached true event
656 maxBudgetReached = true;
657 return true;
658 }
659 else if (budgetChange < 0 && updatedBudgetValue < maxBudgetValue)
660 {
661 // Send when budget is lowered between 100-90%, budget max reached false event
662 if (originalBudgetValue >= maxBudgetValue * 0.9)
663 {
664 maxBudgetReached = false;
665 return true;
666 }
667 }
668 // Do not send max budget reached event
669 return false;
670 }
671
672 //------------------------------------------------------------------------------------------------
673 protected void FilterAvailableBudgets(inout notnull array<ref SCR_EntityBudgetValue> budgetCosts)
674 {
676 for (int i = budgetCosts.Count() - 1; i >= 0; i--)
677 {
678 budget = budgetCosts[i];
679 if (!IsBudgetAvailable(budget.GetBudgetType()))
680 budgetCosts.Remove(i);
681 }
682 }
683
684 //------------------------------------------------------------------------------------------------
685 protected void FilterAvailableBudgetsDontDiscardCampaignBudget(inout notnull array<ref SCR_EntityBudgetValue> budgetCosts)
686 {
688 for (int i = budgetCosts.Count() - 1; i >= 0; i--)
689 {
690 budget = budgetCosts[i];
691
692 if(budget.GetBudgetType() == EEditableEntityBudget.CAMPAIGN)
693 continue;
694
695 if (!IsBudgetAvailable(budget.GetBudgetType()))
696 budgetCosts.Remove(i);
697 }
698 }
699
700 //------------------------------------------------------------------------------------------------
703 SCR_EditableEntityCoreBudgetSetting GetBudgetSetting(EEditableEntityBudget budgetType)
704 {
705 return m_BudgetSettingsMap.Get(budgetType);
706 }
707
708 //------------------------------------------------------------------------------------------------
710 {
711 if (!m_MaxBudgets || m_MaxBudgets.IsEmpty())
712 return 0;
713
714 return m_MaxBudgets[0].GetBudgetType();
715 }
716
717 //------------------------------------------------------------------------------------------------
720 {
721 if (!m_RplComponent)
722 return;
723
724 if (m_RplComponent.Role() != RplRole.Proxy)
725 return;
726
728 }
729
730 //------------------------------------------------------------------------------------------------
732 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
734 {
735 array<ref SCR_EditableEntityCoreBudgetSetting> outBudgets = {};
736 m_EntityCore.GetBudgets(outBudgets);
737
738 foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : outBudgets)
739 {
740 Rpc(RpcOwner_UpdateBudget, budgetSetting.GetBudgetType(), budgetSetting.GetCurrentBudget());
741 }
742 }
743
744 //------------------------------------------------------------------------------------------------
748 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
749 void RpcOwner_UpdateBudget(EEditableEntityBudget budgetType, int currentBudget)
750 {
751 SCR_EditableEntityCoreBudgetSetting budget;
752 if (!m_BudgetSettingsMap.Find(budgetType, budget))
753 return;
754
755 budget.SetCurrentBudget(currentBudget);
756
757 int maxBudget;
758 if (GetMaxBudgetValue(budgetType, maxBudget))
759 {
760 m_BudgetSettingsMap.Insert(budgetType, budget);
761 int currentBudgetValue = budget.GetCurrentBudget();
762 Event_OnBudgetUpdated.Invoke(budgetType, currentBudgetValue, currentBudgetValue, maxBudget);
763 Event_OnBudgetMaxUpdated.Invoke(budgetType, currentBudgetValue, maxBudget);
764 }
765 }
766
767 //------------------------------------------------------------------------------------------------
768 protected bool IsBudgetCapEnabled()
769 {
770 #ifdef ENABLE_DIAG
771 return DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP);
772 #else
773 return true;
774 #endif
775 }
776
777 //------------------------------------------------------------------------------------------------
778 override protected void EOnEditorDebug(array<string> debugTexts)
779 {
780 SCR_EntityBudgetValue maxBudget;
781 foreach (EEditableEntityBudget type, SCR_EditableEntityCoreBudgetSetting budgetSettings : m_BudgetSettingsMap)
782 {
783 GetMaxBudget(type, maxBudget);
784 debugTexts.Insert(string.Format("%1: %2 / %3", typename.EnumToString(EEditableEntityBudget, type), budgetSettings.GetCurrentBudget(), maxBudget.GetBudgetValue()));
785 }
786 }
787
788 //------------------------------------------------------------------------------------------------
789 protected override void EOnEditorInitServer()
790 {
792 m_EntityCore.Event_OnEntityBudgetUpdated.Insert(OnEntityCoreBudgetUpdated);
793
794 //overwrite the nulls with the actual values where valid
795 foreach (SCR_EntityBudgetValue maxBudget : m_MaxBudgets)
796 {
797 m_maxBudgetsInternal.Insert(maxBudget.GetBudgetType(), maxBudget);
798 }
799
800 foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : m_BudgetSettingsMap)
801 {
802 budgetSetting.SetBudgetComponent(this);
803 }
804 }
805
806 //------------------------------------------------------------------------------------------------
807 protected override void EOnEditorDeleteServer()
808 {
809 if (m_EntityCore)
810 m_EntityCore.Event_OnEntityBudgetUpdated.Remove(OnEntityCoreBudgetUpdated);
811
812// if (m_DestroyedEntityFilter)
813// m_DestroyedEntityFilter.GetOnChanged().Remove(OnDestroyedChanged);
814 }
815
816 //------------------------------------------------------------------------------------------------
817 protected override void EOnEditorActivate()
818 {
819// SCR_EntitiesManagerEditorComponent entitiesManager = SCR_EntitiesManagerEditorComponent.Cast(SCR_EntitiesManagerEditorComponent.GetInstance(SCR_EntitiesManagerEditorComponent, true));
820// if (entitiesManager)
821// {
822// //m_DestroyedEntityFilter = entitiesManager.GetFilter(EEditableEntityState.DESTROYED);
823// //m_DestroyedEntityFilter.GetOnChanged().Insert(OnDestroyedChanged);
824// }
825
827
828 if (m_RplComponent && m_RplComponent.Role() != RplRole.Authority)
830 }
831
832 //------------------------------------------------------------------------------------------------
833 protected override void EOnEditorInit()
834 {
836
837 #ifdef ENABLE_DIAG
838 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES, "", "Log Budget Changes", "Editable Entities");
839 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP, "", "Enable Budget Cap", "Editable Entities");
840 DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP, 1);
841 #endif
842
843
844 //overwrite the nulls with the actual values where valid
845 foreach (SCR_EntityBudgetValue maxBudget : m_MaxBudgets)
846 {
847 m_maxBudgetsInternal.Insert(maxBudget.GetBudgetType(), maxBudget);
848 }
849
850 foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : m_BudgetSettingsMap)
851 {
852 budgetSetting.SetBudgetComponent(this);
853 }
854 }
855
856 //------------------------------------------------------------------------------------------------
857 // destructor
859 {
860 #ifdef ENABLE_DIAG
861 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES);
862 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_BUDGET_CAP);
863 #endif
864 }
865}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
EEditableEntityBudget
EEditorPlacingFlags
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
func ScriptInvoker_EntityBudgetUpdated
func ScriptInvoker_EntityBudgetMaxUpdated
ScriptInvokerBase< ScriptInvoker_EntityBudgetMaxReached > ScriptInvoker_EntityBudgetMaxReachedEvent
ScriptInvokerBase< ScriptInvoker_EntityBudgetUpdated > ScriptInvoker_EntityBudgetUpdatedEvent
ScriptInvokerBase< ScriptInvoker_EntityBudgetMaxUpdated > ScriptInvoker_EntityBudgetMaxUpdatedEvent
func ScriptInvoker_EntityBudgetMaxReached
EDamageType type
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Diagnostic and developer menu system.
Definition DiagMenu.c:18
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external bool IsDeleted()
void SCR_BaseEditorComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_EditorManagerEntity GetManager()
void UpdatePreviewCost(notnull array< ref SCR_EntityBudgetValue > budgetCosts)
bool GetEntitySourcePreviewBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void DelayedSetMaxBudgetSetup(EEditableEntityBudget type, int newValue, int playerChangingBudget)
bool GetVehicleOccupiedBudgetCosts(IEntityComponentSource editableEntitySource, EEditorPlacingFlags placingFlags, out notnull array< ref SCR_EntityBudgetValue > budgetCosts, bool includeVehicleCost=true)
bool GetCurrentBudgetSettings(EEditableEntityBudget budgetType, out SCR_EditableEntityCoreBudgetSetting budgetSettings)
ref ScriptInvoker_EntityBudgetMaxUpdatedEvent Event_OnBudgetMaxUpdated
void SetMultiMaxBudgetValues(notnull map< EEditableEntityBudget, int > budgets, int playerChangingBudget)
ref ScriptInvoker Event_OnBudgetPreviewUpdated
bool IsBudgetAvailable(EEditableEntityBudget type)
void UpdateMaxBudgetOwner(int budgetType, int oldMaxBudget, int newMaxBudget)
bool CanPlace(SCR_EntityBudgetValue budgetCost, out EEditableEntityBudget blockingBudget)
bool CanPlaceEntityType(EEditableEntityType entityType, out notnull array< ref SCR_EntityBudgetValue > budgetCosts, out EEditableEntityBudget blockingBudget)
bool GetMaxBudget_Old(EEditableEntityBudget type, out SCR_EntityBudgetValue budget)
SCR_EditableEntityCoreBudgetSetting GetBudgetSetting(EEditableEntityBudget budgetType)
bool GetCurrentBudgetInfo(EEditableEntityBudget budgetType, out SCR_UIInfo blockingBudgetInfo)
ref ScriptInvoker_EntityBudgetMaxReachedEvent Event_OnBudgetMaxReached
bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out EEditableEntityBudget blockingBudget, bool showNotification)
bool CanPlace(notnull array< ref SCR_EntityBudgetValue > budgetCosts, out EEditableEntityBudget blockingBudget)
bool GetMaxBudget(EEditableEntityBudget type, out SCR_EntityBudgetValue budget)
void RefreshBudgetSettings()
Get default budget definitions from core, budget values not synced on client, use GetCurrentBudget fo...
void GetEntityTypeBudgetCost(EEditableEntityType entityType, out array< ref SCR_EntityBudgetValue > budgetCosts)
void OnEntityCoreBudgetUpdated(EEditableEntityBudget entityBudget, int originalBudgetValue, int budgetChange, int updatedBudgetValue)
bool CheckMaxBudgetReached(EEditableEntityBudget entityBudget, int budgetChange, int originalBudgetValue, int updatedBudgetValue, int maxBudgetValue, out bool maxBudgetReached)
int GetEntityTypeBudgetCost(EEditableEntityBudget budgetType)
void DelayedSetMaxBudget(int playerChangingBudget)
SCR_EditableEntityCore m_EntityCore
bool CanPlaceEntitySource(IEntityComponentSource editableEntitySource, out EEditableEntityBudget blockingBudget, bool isPlacingPlayer=false, bool updatePreview=true, bool showNotification=true)
void RpcOwner_UpdateBudget(EEditableEntityBudget budgetType, int currentBudget)
ref array< ref SCR_EntityBudgetValue > m_MaxBudgets
bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out notnull array< ref SCR_EntityBudgetValue > budgetCosts, out EEditableEntityBudget blockingBudget, bool showNotification)
void SetMaxBudgetValue(EEditableEntityBudget type, int newValue)
ref map< EEditableEntityBudget, ref SCR_EntityBudgetValue > m_maxBudgetsInternal
SCR_BaseEditableEntityFilter m_DestroyedEntityFilter
void GetBudgetCostsDontDiscardCampaignBudget(IEntityComponentSource editableEntitySource, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
ref map< EEditableEntityBudget, int > m_DelayedSetMaxBudgetsMap
ref map< EEditableEntityBudget, SCR_EditableEntityCoreBudgetSetting > m_BudgetSettingsMap
void FilterAvailableBudgetsDontDiscardCampaignBudget(inout notnull array< ref SCR_EntityBudgetValue > budgetCosts)
bool GetEntityPreviewBudgetCosts(SCR_EditableEntityUIInfo entityUIInfo, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
EEditableEntityBudget GetFirstAvailableBudget()
bool GetVehicleOccupiedBudgetCosts(SCR_EditableVehicleUIInfo editableUIInfo, EEditorPlacingFlags placingFlags, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void SetCurrentBudgetValue(EEditableEntityBudget budgetType, int value)
void FilterAvailableBudgets(inout notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void GetBudgetCosts(IEntityComponentSource editableEntitySource, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void OnEntityCoreBudgetUpdatedOwner(EEditableEntityBudget entityBudget, int budgetValue, int budgetChange, bool sendBudgetMaxEvent, bool budgetMaxReached)
bool GetEntityPreviewBudgetCostsDontDiscardCampaignBudget(SCR_EditableEntityUIInfo entityUIInfo, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
ref ScriptInvoker_EntityBudgetUpdatedEvent Event_OnBudgetUpdated
int GetCurrentBudgetValue(EEditableEntityBudget type)
bool CanPlace(int currentBudget, int budgetChange, int maxBudget)
void GetBudgets(out notnull array< ref SCR_EditableEntityCoreBudgetSetting > budgets)
bool CanPlaceResult(bool canPlace, bool showNotification)
bool GetMaxBudgetValue(EEditableEntityBudget type, out int maxBudget)
void EOnEditorDebug(array< string > debugTexts)
EEditableEntityType GetEntityType()
bool GetEntityBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
void GetEntityChildrenBudgetCost(out notnull array< ref SCR_EntityBudgetValue > outBudgets)
Get only Entity's children budget costs, i.e. cost of entities inside a composition entitiy.
proto external GenericEntity GetOwner()
Get owner entity.
Definition Types.c:486
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
SCR_FieldOfViewSettings Attribute
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134