4 static const float RESOURCES_LOWER_LIMIT = 0.0;
14 [
Attribute(defvalue:
EResourceType.SUPPLIES.ToString(), uiwidget:
UIWidgets.ComboBox,
desc:
"Sets the type of Resource to be used.\nOnly a transaction matching Resource types can be successfully concluded.", enums: ParamEnumArray.FromEnum(
EResourceType))]
120 [
Obsolete(
"Use SCR_ResourceActor::Update(WorldTimestamp timestamp) instead.")]
158 protected float m_fAggregatedResourceValue = -1.0;
159 protected float m_fAggregatedMaxResourceValue = -1.0;
170 float GetResourceGridRange()
177 float GetAggregatedResourceValue()
184 float GetAggregatedMaxResourceValue()
191 int GetContainerCount()
212 SCR_ResourceContainerQueueBase GetContainerQueue()
221 if (!m_OnResourcesChangedInvoker)
224 return m_OnResourcesChangedInvoker;
232 if (!m_OnMaxResourcesChangedInvoker)
235 return m_OnMaxResourcesChangedInvoker;
255 bool IsAllowed(notnull SCR_ResourceContainer container)
260 switch (m_eResourceRights)
266 return m_Owner == container.GetOwner();
278 FactionAffiliationComponent interactorFactionComponent =
m_ResourceComponent.GetFactionAffiliationComponent();
280 if (!interactorFactionComponent)
283 FactionAffiliationComponent containerFactionComponent = container.GetComponent().GetFactionAffiliationComponent();
285 if (!containerFactionComponent)
288 Faction interactorFaction = interactorFactionComponent.GetAffiliatedFaction();
289 Faction containerFaction = containerFactionComponent.GetAffiliatedFaction();
291 if (!interactorFaction || !containerFaction)
294 return interactorFaction == containerFaction || interactorFaction.IsFactionFriendly(containerFaction);
312 switch (m_eResourceRights)
323 FactionAffiliationComponent interactorFactionComponent =
m_ResourceComponent.GetFactionAffiliationComponent();
325 if (!interactorFactionComponent)
328 SCR_ResourceComponent containerResourceComponent = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
330 if (!containerResourceComponent)
333 SCR_ResourceContainer container;
335 if (!containerResourceComponent.GetContainer(resourceType, container))
341 FactionAffiliationComponent containerrFactionComponent = container.GetComponent().GetFactionAffiliationComponent();
343 if (!containerrFactionComponent)
346 return interactorFactionComponent.GetAffiliatedFaction() == containerrFactionComponent.GetAffiliatedFaction();
359 bool CanInteractWith(notnull SCR_ResourceContainer container)
361 return IsAllowed(container) && container.IsAllowed(
this);
368 int FindContainer(notnull SCR_ResourceContainer container)
370 return SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX;
393 bool RegisterContainer(notnull SCR_ResourceContainer container)
402 bool RegisterContainerForced(notnull SCR_ResourceContainer container)
411 bool UnregisterContainer(
int containerIndex)
420 bool UnregisterContainer(notnull SCR_ResourceContainer container)
443 void UpdateContainerResourceValue(SCR_ResourceContainer container,
float previousValue);
449 void UpdateContainerMaxResourceValue(SCR_ResourceContainer container,
float previousValue);
454 void OnResourceGridUpdated(notnull SCR_ResourceGrid grid)
465 m_fAggregatedResourceValue = GetAggregatedResourceValue();
467 if (m_OnResourcesChangedInvoker)
468 m_OnResourcesChangedInvoker.Invoke(
this, previousValue);
478 void OnMaxResourcesChanged(
float previousValue)
480 m_fAggregatedMaxResourceValue = GetAggregatedMaxResourceValue();
482 if (m_OnMaxResourcesChangedInvoker)
483 m_OnMaxResourcesChangedInvoker.Invoke(
this, previousValue);
493 void OnContainerRegistered(notnull SCR_ResourceContainer container)
495 container.LinkInteractor(
this);
497 OnMaxResourcesChanged(GetAggregatedMaxResourceValue() - container.GetMaxResourceValue());
502 void OnContainerUnregistered(notnull SCR_ResourceContainer container)
504 container.UnlinkInteractor(
this);
506 OnMaxResourcesChanged(GetAggregatedMaxResourceValue() + container.GetMaxResourceValue());
515 m_ResourceComponent = SCR_ResourceComponent.Cast(owner.FindComponent(SCR_ResourceComponent));
519 override void Clear()
523 m_fAggregatedResourceValue = -1.0;
524 m_fAggregatedMaxResourceValue = -1.0;
529class SCR_ResourceConsumer : SCR_ResourceInteractor
531 protected static const int CODEC_CONSUMER_PACKET_BYTESIZE = 38;
536 [
Attribute(defvalue:
"0.0", uiwidget: UIWidgets.SpinBox,
desc:
"Sets the range in which Resource is sought.",
params:
"0.0 10000.0 1.0")]
537 protected float m_fResourceRange;
539 [
Attribute(
"1", uiwidget: UIWidgets.SpinBox,
params:
string.Format(
"0.0 %1 1.0",
float.MAX))]
540 protected float m_fBuyMultiplier;
542 [
Attribute(uiwidget: UIWidgets.SpinBox,
params:
string.Format(
"0.0 %1 1.0",
float.MAX))]
543 protected float m_fSellMultiplier;
545 [
Attribute(uiwidget: UIWidgets.CheckBox)]
546 protected bool m_bIsIgnoringItself;
549 protected ref SCR_ResourceConsumerContainerQueue m_ContainerQueue;
551 protected bool m_bIsConsuming;
552 protected bool m_bIsExchanging;
555 protected ref
ScriptInvoker m_OnSellMultiplierChangedInvoker;
556 protected ref
ScriptInvoker m_OnConsumtionStateChangedInvoker;
560 override float GetResourceGridRange()
562 return m_fResourceRange;
567 float GetResourceRange()
569 return m_fResourceRange;
574 float GetBuyMultiplier()
576 return m_fBuyMultiplier;
581 float GetSellMultiplier()
583 return m_fSellMultiplier;
587 override float GetAggregatedResourceValue()
589 if (!m_ContainerQueue)
590 return m_fAggregatedResourceValue;
592 return m_ContainerQueue.GetAggregatedResourceValue();
596 override float GetAggregatedMaxResourceValue()
598 if (!m_ContainerQueue)
599 return m_fAggregatedMaxResourceValue;
601 return m_ContainerQueue.GetAggregatedMaxResourceValue();
605 override int GetContainerCount()
607 if (!m_ContainerQueue)
610 return m_ContainerQueue.GetContainerCount();
614 override SCR_ResourceContainerQueueBase GetContainerQueue()
616 return m_ContainerQueue;
623 if (!m_OnResourceRangeChangedInvoker)
626 return m_OnResourceRangeChangedInvoker;
633 if (!m_OnBuyMultiplierChangedInvoker)
636 return m_OnBuyMultiplierChangedInvoker;
643 if (!m_OnSellMultiplierChangedInvoker)
646 return m_OnSellMultiplierChangedInvoker;
654 if (!m_OnConsumtionStateChangedInvoker)
657 return m_OnConsumtionStateChangedInvoker;
664 if (!m_OnExchangeStateChangedInvoker)
667 return m_OnExchangeStateChangedInvoker;
674 return m_eGeneratorIdentifier;
680 return m_eGeneratorIdentifier;
685 bool IsIgnoringItself()
687 return m_bIsIgnoringItself;
694 return m_bIsConsuming;
701 return m_bIsExchanging;
705 override bool ShouldUpdate()
711 override bool CanInteractWith(notnull SCR_ResourceContainer container)
713 return (!m_bIsIgnoringItself || container.GetOwner() !=
m_Owner) && super.CanInteractWith(container);
717 override int FindContainer(notnull SCR_ResourceContainer container)
719 if (!m_ContainerQueue)
720 return super.FindContainer(container);
722 return m_ContainerQueue.FindContainer(container);
729 bool SetResourceRange(
float value,
bool notifyChange =
true)
731 float previousValue = m_fResourceRange;
732 m_fResourceRange = Math.Max(value, 0.0);
734 if (previousValue == m_fResourceRange)
738 OnResourceRangeChanged(previousValue);
747 bool SetBuyMultiplier(
float value,
bool notifyChange =
true)
749 float previousValue = m_fBuyMultiplier;
750 m_fBuyMultiplier = Math.Max(value, 0.0);
752 if (previousValue == m_fBuyMultiplier)
756 OnBuyMultiplierChanged(previousValue);
765 bool SetSellMultiplier(
float value,
bool notifyChange =
true)
767 float previousValue = m_fSellMultiplier;
768 m_fSellMultiplier = Math.Max(value, 0.0);
770 if (previousValue == m_fSellMultiplier)
774 OnSellMultiplierChanged(previousValue);
785 bool EnableConsumtion(
bool shouldEnable,
bool notifyChange =
true)
787 bool previousValue = m_bIsConsuming;
788 m_bIsConsuming = shouldEnable;
790 if (shouldEnable == m_bIsConsuming)
794 OnConsumtionStateChanged(previousValue);
804 bool EnableExchange(
bool shouldEnable,
bool notifyChange =
true)
806 bool previousValue = m_bIsExchanging;
807 m_bIsExchanging = shouldEnable;
809 if (previousValue == m_bIsExchanging)
813 OnExchangeStateChanged(previousValue);
819 override bool RegisterContainer(notnull SCR_ResourceContainer container)
821 if (CanInteractWith(container)
823 && m_ContainerQueue.RegisterContainer(container) != SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX)
825 OnContainerRegistered(container);
834 override bool RegisterContainerForced(notnull SCR_ResourceContainer container)
836 if (m_ContainerQueue && m_ContainerQueue.RegisterContainer(container) != SCR_ResourceContainerQueueBase.INVALID_CONTAINER_INDEX)
838 OnContainerRegistered(container);
847 override bool UnregisterContainer(
int containerIndex)
849 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(containerIndex);
853 override bool UnregisterContainer(notnull SCR_ResourceContainer container)
855 return m_ContainerQueue && m_ContainerQueue.PopContainerAt(m_ContainerQueue.FindContainer(container));
865 GetGame().GetResourceGrid().UpdateInteractor(
this);
872 if (resourceCost > response.GetAvailableSupply())
879 if (resourceCost != 0.0 && response.GetAvailableSupply() == 0)
898 if (!m_bIsConsuming || response.GetReason() !=
EResourceReason.SUFFICIENT)
902 SCR_ResourceContainer container;
903 SCR_ResourceEncapsulator encapsulator;
905 m_ContainerQueue.PerformSorting();
907 int containerCount = m_ContainerQueue.GetContainerCount();
909 for (
int i = 0; i < containerCount && resourceCost > 0.0; i++)
911 container = m_ContainerQueue.GetContainerAt(i);
913 resourceCost -= resourceUsed;
935 vector origin = GetOwnerOrigin();
941 DebugTextWorldSpace.Create(
GetGame().GetWorld(),
string.Format(
" %1 \n %2 containers \n %3 / %4 resources \n %5 m ", m_sDebugName, GetContainerCount(), GetAggregatedResourceValue(), GetAggregatedMaxResourceValue(), m_fResourceRange),
DebugTextFlags.ONCE |
DebugTextFlags.CENTER |
DebugTextFlags.FACE_CAMERA, origin[0], origin[1] + m_fResourceRange, origin[2], 10.0, 0xFFFFFFFF, color.PackToInt());
943 if (m_ContainerQueue)
944 m_ContainerQueue.DebugDraw();
948 override void UpdateContainerResourceValue(SCR_ResourceContainer container,
float previousValue)
951 m_ContainerQueue.UpdateContainerResourceValue(container.
GetResourceValue(), previousValue)
956 override void UpdateContainerMaxResourceValue(SCR_ResourceContainer container,
float previousValue)
958 OnMaxResourcesChanged(
959 m_ContainerQueue.UpdateContainerMaxResourceValue(container.
GetMaxResourceValue(), previousValue)
964 protected void OnResourceRangeChanged(
float previousValue)
966 if (m_OnResourceRangeChangedInvoker)
967 m_OnResourceRangeChangedInvoker.Invoke(
this, previousValue);
971 protected void OnBuyMultiplierChanged(
float previousValue)
973 if (m_OnBuyMultiplierChangedInvoker)
974 m_OnBuyMultiplierChangedInvoker.Invoke(
this, previousValue);
978 protected void OnSellMultiplierChanged(
float previousValue)
980 if (m_OnSellMultiplierChangedInvoker)
981 m_OnSellMultiplierChangedInvoker.Invoke(
this, previousValue);
986 protected void OnConsumtionStateChanged(
float previousValue)
988 if (m_OnConsumtionStateChangedInvoker)
989 m_OnConsumtionStateChangedInvoker.Invoke(
this, previousValue);
993 protected void OnExchangeStateChanged(
float previousValue)
995 if (m_OnExchangeStateChangedInvoker)
996 m_OnExchangeStateChangedInvoker.Invoke(
this, previousValue);
1002 super.Initialize(owner);
1009 m_bIsConsuming =
true;
1011 if (m_ContainerQueue)
1012 m_ContainerQueue.Initialize(
this);
1015 RegisterContainer(container);
1019 override void Clear()
1023 if (m_ContainerQueue)
1024 m_ContainerQueue.Clear();
1026 GetGame().GetResourceSystemSubscriptionManager().OnResourceInteractorDeleted(
this);
1030 protected bool PropCompareNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
1034 return snapshot.Compare(componentRplId, 4)
1035 && snapshot.Compare(m_fResourceRange, 4)
1036 && snapshot.Compare(m_fAggregatedResourceValue, 4)
1037 && snapshot.Compare(m_fAggregatedMaxResourceValue, 4)
1038 && snapshot.Compare(m_fBuyMultiplier, 4)
1039 && snapshot.Compare(m_fSellMultiplier, 4)
1040 && snapshot.Compare(m_bIsConsuming, 1)
1041 && snapshot.Compare(m_bIsExchanging, 1)
1042 && snapshot.Compare(m_eResourceRights, 4)
1044 && snapshot.Compare(m_eGeneratorIdentifier, 4);
1048 protected bool ExtractNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
1050 float aggregatedResourceValue = GetAggregatedResourceValue();
1051 float aggregatedMaxResourceValue = GetAggregatedMaxResourceValue();
1054 snapshot.SerializeBytes(componentRplId, 4);
1055 snapshot.SerializeBytes(m_fResourceRange, 4);
1056 snapshot.SerializeBytes(aggregatedResourceValue, 4);
1057 snapshot.SerializeBytes(aggregatedMaxResourceValue, 4);
1058 snapshot.SerializeBytes(m_fBuyMultiplier, 4);
1059 snapshot.SerializeBytes(m_fSellMultiplier, 4);
1060 snapshot.SerializeBytes(m_bIsConsuming, 1);
1061 snapshot.SerializeBytes(m_bIsExchanging, 1);
1062 snapshot.SerializeBytes(m_eResourceRights, 4);
1064 snapshot.SerializeBytes(m_eGeneratorIdentifier, 4);
1070 protected bool InjectNetworkedVariables(SSnapSerializerBase snapshot, ScriptCtx hint)
1072 RplId componentRplId;
1074 snapshot.SerializeBytes(componentRplId, 4);
1075 snapshot.SerializeBytes(m_fResourceRange, 4);
1076 snapshot.SerializeBytes(m_fAggregatedResourceValue, 4);
1077 snapshot.SerializeBytes(m_fAggregatedMaxResourceValue, 4);
1078 snapshot.SerializeBytes(m_fBuyMultiplier, 4);
1079 snapshot.SerializeBytes(m_fSellMultiplier, 4);
1080 snapshot.SerializeBytes(m_bIsConsuming, 1);
1081 snapshot.SerializeBytes(m_bIsExchanging, 1);
1082 snapshot.SerializeBytes(m_eResourceRights, 4);
1084 snapshot.SerializeBytes(m_eGeneratorIdentifier, 4);
1101 static void Encode(SSnapSerializerBase snapshot, ScriptCtx ctx, ScriptBitSerializer packet)
1103 snapshot.Serialize(packet, SCR_ResourceConsumer.CODEC_CONSUMER_PACKET_BYTESIZE);
1112 static bool Decode(ScriptBitSerializer packet, ScriptCtx ctx, SSnapSerializerBase snapshot)
1114 return snapshot.Serialize(packet, SCR_ResourceConsumer.CODEC_CONSUMER_PACKET_BYTESIZE);
1123 static bool SnapCompare(SSnapSerializerBase lhs, SSnapSerializerBase rhs , ScriptCtx ctx)
1125 return lhs.CompareSnapshots(rhs, SCR_ResourceConsumer.CODEC_CONSUMER_PACKET_BYTESIZE);
1134 static bool PropCompare(SCR_ResourceConsumer instance, SSnapSerializerBase snapshot, ScriptCtx ctx)
1136 return instance.PropCompareNetworkedVariables(snapshot, ctx);
1145 static bool Extract(SCR_ResourceConsumer instance, ScriptCtx ctx, SSnapSerializerBase snapshot)
1147 return instance.ExtractNetworkedVariables(snapshot, ctx);
1156 static bool Inject(SSnapSerializerBase snapshot, ScriptCtx ctx, SCR_ResourceConsumer instance)
1158 return instance.InjectNetworkedVariables(snapshot, ctx);
ArmaReforgerScripted GetGame()
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
void SetGridUpdateId(int gridUpdateId)
bool IsGridUpdateIdGreaterThan(int gridUpdateId)
void UpdateLastPosition()
Updates the serial number for the current processing call of the resource grid onto this component.
EResourceType m_eResourceType
void SCR_ResourceConsumtionResponse(float availableResource=0, float resourceMultiplier=0, float range=0, EResourceReason reasonCode=EResourceReason.UNAVAILABLE)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void OnResourcesChanged(SCR_ResourceInteractor interactor, float previousSupplies)
EResourceType GetResourceType()
SCR_ResourceComponent m_ResourceComponent
enum EVehicleType IEntity
SCR_ResourceComponent m_ResourceComponent
void ~SCR_ResourceActor()
EResourceType m_eResourceType
SCR_ResourceComponent GetComponent()
static const int CODEC_GENERATOR_PACKET_BYTESIZE
void UpdateInner(float timeslice)
void Update(float timeslice)
static const float UPDATE_PERIOD
void Update(WorldTimestamp timestamp)
EResourceRights GetResourceRight()
bool IsGridUpdateIdGreaterThan(int gridUpdateId)
void SetGridUpdateId(int gridUpdateId)
void SetResourceRights(EResourceRights rights)
EResourceRights m_eResourceRights
SCR_ResourceEncapsulator GetResourceEncapsulator()
bool DecreaseResourceValue(float value, bool notifyChange=true)
float GetMaxResourceValue()
void RequestConsumtion(float resourceCost, bool notifyChange=true)
SCR_FieldOfViewSettings Attribute
proto native void Clear()
Remove all calls from list.