19#define BUDGET_OPTIMIZATION_CHECKS
23 const int DEFAULT_MAX_BUDGET = 100;
24 const int DEFAULT_MIN_COST = 1;
55 array<ref SCR_EntityBudgetValue> budgetCosts = {};
71 bool canPlace =
false;
73 canPlace =
CanPlace(budgetCosts, blockingBudget);
96 array<ref SCR_EntityBudgetValue> budgetCosts = {};
108 canPlace = canPlace &&
CanPlace(budgetCosts, blockingBudget);
120 if (!editableEntitySource)
142 return CanPlace(budgetCosts, blockingBudget);
157 if (!
CanPlace(budgetCost, blockingBudget))
172 int budgetChange = budgetCost.GetBudgetValue();
173 if (!
CanPlace(originalBudgetValue, budgetChange, maxBudgetValue))
175 blockingBudget = budgetType;
185 protected bool CanPlace(
int currentBudget,
int budgetChange,
int maxBudget)
187 return currentBudget + budgetChange <= maxBudget;
202 array<ref SCR_EntityBudgetValue> entityChildrenBudgetCosts = {};
224 array<ref SCR_EntityBudgetValue> entityChildrenBudgetCosts = {};
240 if (!editableEntitySource)
276 array<ref SCR_EntityBudgetValue> vehicleOccupantsBudgetCosts = {};
280 editableUIInfo.GetFillBudgetCostsOfCrew(vehicleOccupantsBudgetCosts);
286 editableUIInfo.GetFillBudgetCostsOfPassengers(vehicleOccupantsBudgetCosts);
302 int budgetValue = budgetCost.GetBudgetValue();
307 float max = maxBudget;
310 float newBudgetPercent;
315 float currentBudgetPercent = currentBudget / max * 100;
316 int newBudget = currentBudget + budgetValue;
318 newBudgetPercent = newBudget / max * 100;
320 budgetChange = newBudgetPercent - currentBudgetPercent;
324 newBudgetPercent = 100;
349 #ifdef BUDGET_OPTIMIZATION_CHECKS
352 if(result && !budget)
354 Print(
"GetMaxBudget: Budget type wasn't defined!",
LogLevel.ERROR);
373 if (maxBudget.GetBudgetType() ==
type)
392 maxBudget = budgetValue.GetBudgetValue();
408 oldValue = maxBudget.GetBudgetValue();
409 maxBudget.SetBudgetValue(newValue);
466 return budgetSettings.GetMinBudgetCost();
468 return DEFAULT_MIN_COST;
477 SCR_EditableEntityCoreBudgetSetting budgetSettings;
481 return budgetSettings.GetCurrentBudget() + budgetSettings.GetReservedBudget();
490 int originalBudgetValue, budgetChange, maxBudgetValue;
491 SCR_EditableEntityCoreBudgetSetting budgetSettings;
494 originalBudgetValue = budgetSettings.GetCurrentBudget();
495 budgetChange = budgetSettings.SetCurrentBudget(value);
497 if (budgetChange != value - originalBudgetValue)
500 bool budgetMaxReached;
501 bool sendBudgetMaxEvent =
CheckMaxBudgetReached(budgetType, budgetChange, originalBudgetValue, value, maxBudgetValue, budgetMaxReached);
514 SCR_EditableEntityCoreBudgetSetting budgetSettings;
517 blockingBudgetInfo = budgetSettings.GetInfo();
525 void GetBudgets(out notnull array<ref SCR_EditableEntityCoreBudgetSetting> budgets)
529 budgets.Insert(setting);
548 array<ref SCR_EditableEntityCoreBudgetSetting> outBudgets = {};
551 SCR_EditableEntityCoreBudgetSetting budget;
552 for (
int i = outBudgets.Count() - 1; i >= 0; i--)
554 budget = outBudgets[i];
560 int currentBudgetValue = budget.GetCurrentBudget();
566 outBudgets.RemoveOrdered(i);
576 Print(
string.Format(
"Updated maximum budget received for type %1: %2", budgetType, newMaxBudget),
LogLevel.NORMAL);
580 maxBudget.SetBudgetValue(newMaxBudget);
584 if (oldMaxBudget == 0 || (currentBudget > oldMaxBudget && currentBudget < newMaxBudget))
586 else if (newMaxBudget == 0 || (currentBudget < oldMaxBudget && currentBudget > newMaxBudget))
595 if (showNotification)
623 bool budgetMaxReached;
624 bool sendBudgetMaxEvent =
CheckMaxBudgetReached(entityBudget, budgetChange, originalBudgetValue, updatedBudgetValue, maxBudgetValue, budgetMaxReached);
634 Print(
string.Format(
"Updated budget received for type %1: %2", entityBudget, budgetValue),
LogLevel.NORMAL);
637 SCR_EditableEntityCoreBudgetSetting budgetSettings;
640 int currentBudget = budgetSettings.GetCurrentBudget();
641 int ownerBudgetChange = budgetSettings.SetCurrentBudget(budgetValue);
645 if (sendBudgetMaxEvent)
653 if (budgetChange >= 0 && originalBudgetValue + budgetChange >= maxBudgetValue)
656 maxBudgetReached =
true;
659 else if (budgetChange < 0 && updatedBudgetValue < maxBudgetValue)
662 if (originalBudgetValue >= maxBudgetValue * 0.9)
664 maxBudgetReached =
false;
676 for (
int i = budgetCosts.Count() - 1; i >= 0; i--)
678 budget = budgetCosts[i];
680 budgetCosts.Remove(i);
688 for (
int i = budgetCosts.Count() - 1; i >= 0; i--)
690 budget = budgetCosts[i];
696 budgetCosts.Remove(i);
735 array<ref SCR_EditableEntityCoreBudgetSetting> outBudgets = {};
738 foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : outBudgets)
751 SCR_EditableEntityCoreBudgetSetting budget;
755 budget.SetCurrentBudget(currentBudget);
761 int currentBudgetValue = budget.GetCurrentBudget();
784 debugTexts.Insert(
string.Format(
"%1: %2 / %3",
typename.EnumToString(
EEditableEntityBudget,
type), budgetSettings.GetCurrentBudget(), maxBudget.GetBudgetValue()));
802 budgetSetting.SetBudgetComponent(
this);
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");
852 budgetSetting.SetBudgetComponent(
this);
ArmaReforgerScripted GetGame()
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
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
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()
RplComponent m_RplComponent
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)
override void EOnEditorActivate()
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)
override void EOnEditorInit()
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)
ref ScriptInvoker Event_OnBudgetPreviewReset
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)
void CanPlaceOwner(bool canPlace)
ref array< ref SCR_EntityBudgetValue > m_MaxBudgets
bool CanPlaceEntityInfo(SCR_EditableEntityUIInfo info, out notnull array< ref SCR_EntityBudgetValue > budgetCosts, out EEditableEntityBudget blockingBudget, bool showNotification)
bool m_bListenToMaxBudgetDelay
void SetMaxBudgetValue(EEditableEntityBudget type, int newValue)
ref map< EEditableEntityBudget, ref SCR_EntityBudgetValue > m_maxBudgetsInternal
SCR_BaseEditableEntityFilter m_DestroyedEntityFilter
void ~SCR_BudgetEditorComponent()
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)
bool IsBudgetCapEnabled()
EEditableEntityBudget GetFirstAvailableBudget()
bool GetVehicleOccupiedBudgetCosts(SCR_EditableVehicleUIInfo editableUIInfo, EEditorPlacingFlags placingFlags, out notnull array< ref SCR_EntityBudgetValue > budgetCosts)
void DemandBudgetUpdateFromServer()
void RpcServer_UpdateBudget()
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)
override void EOnEditorDeleteServer()
override void EOnEditorInitServer()
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.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
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.
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.