22 protected ref array<ref SCR_ResourceContainer> m_aContainers;
27 array<ref SCR_ResourceContainer> GetContainers()
33 override static array<typename> Requires(IEntityComponentSource src)
35 return { RplComponent };
72 [
Attribute(
desc:
"List of all disabled resource types", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(
EResourceType)),
RplProp(onRplName:
"OnResourceTypeEnabledChanged")]
76 [
Attribute(
desc:
"Any ResourceType that is set here cannot be enabled or disabled in runtime for this entity by editor", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(
EResourceType))]
111 [
Attribute(defvalue:
"0.4 0.0 0.467 0.267 ", uiwidget: UIWidgets.ColorPicker,
category:
"Debugging")]
114 [
RplProp(onRplName:
"OnVisibilityChanged")]
152 return disabledResourceTypes.Count();
175 if ((
index < 0) == enable)
183 Replication.BumpMe();
198 if ((gameMode && gameMode.IsMaster()) || (!gameMode && Replication.IsServer()))
224 static SCR_ResourceComponent FindResourceComponent(IEntity entity,
bool ignoreChildIfHasStorage =
false)
231 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
232 if (resourceComponent)
233 return resourceComponent;
236 if (Vehicle.Cast(entity))
238 SlotManagerComponent slotManager = SlotManagerComponent.Cast(entity.FindComponent(SlotManagerComponent));
242 array<EntitySlotInfo> outSlotInfos = {};
243 slotManager.GetSlotInfos(outSlotInfos);
248 slot = slotInfo.GetAttachedEntity();
253 resourceComponent = SCR_ResourceComponent.Cast(slot.FindComponent(SCR_ResourceComponent));
254 if (resourceComponent)
257 if (!ignoreChildIfHasStorage)
258 return resourceComponent;
261 if (!slot.FindComponent(ScriptedBaseInventoryStorageComponent))
262 return resourceComponent;
267 else if (Vehicle.Cast(entity.GetParent()))
273 if (inventoryItem.GetParentSlot())
277 return SCR_ResourceComponent.FindResourceComponent(entity.GetParent(), ignoreChildIfHasStorage);
320 vector ownerOrigin =
GetOwner().GetOrigin();
356 if (higherLimitPosition == 0)
362 while (
position < higherLimitPosition)
370 || resourceType != encapsulator.GetResourceType())
389 if (higherLimitPosition == 0)
394 while (
position < higherLimitPosition)
402 || resourceType != encapsulator.GetResourceType())
417 EResourceType compareResourceType = encapsulator.GetResourceType();
419 if (resourceType > compareResourceType)
421 else if (resourceType < compareResourceType)
422 higherLimitPosition = comparePosition;
444 if (encapsulatorCount == 0)
447 array<SCR_ResourceEncapsulator> encapsulators = {};
449 encapsulators.Reserve(encapsulatorCount);
453 encapsulators.Insert(encapsulator);
456 return encapsulators;
470 if (higherLimitPosition == 0)
476 while (
position < higherLimitPosition)
484 || resourceType != container.GetResourceType())
503 if (higherLimitPosition == 0)
508 while (
position < higherLimitPosition)
516 || resourceType != container.GetResourceType())
531 EResourceType compareResourceType = container.GetResourceType();
533 if (resourceType > compareResourceType)
537 else if (resourceType < compareResourceType)
539 higherLimitPosition = comparePosition;
559 if (containerCount == 0)
562 array<SCR_ResourceContainer> containers = {};
564 containers.Reserve(containerCount);
568 containers.Insert(container);
584 if (higherLimitPosition == 0)
588 SCR_ResourceConsumer consumer;
590 while (
position < higherLimitPosition)
598 || identifier != consumer.GetGeneratorIdentifier()
599 || resourceType != consumer.GetResourceType())
619 if (higherLimitPosition == 0)
624 while (
position < higherLimitPosition)
632 || identifier != consumer.GetGeneratorIdentifier()
633 || resourceType != consumer.GetResourceType())
648 EResourceType compareResourceType = consumer.GetResourceType();
651 if (identifier > comapareIdentifier)
655 else if (identifier < comapareIdentifier)
657 higherLimitPosition = comparePosition;
659 else if (resourceType > compareResourceType)
663 else if (resourceType < compareResourceType)
665 higherLimitPosition = comparePosition;
684 if (consumerCount == 0)
687 array<SCR_ResourceConsumer> consumers = {};
688 consumers.Reserve(consumerCount);
692 consumers.Insert(container);
708 if (higherLimitPosition == 0)
714 while (
position < higherLimitPosition)
722 || identifier != generator.GetIdentifier()
723 || resourceType != generator.GetResourceType())
742 if (higherLimitPosition == 0)
747 while (
position < higherLimitPosition)
755 || identifier != generator.GetIdentifier()
756 || resourceType != generator.GetResourceType())
771 EResourceType compareResourceType = generator.GetResourceType();
774 if (identifier > comapareIdentifier)
778 else if (identifier < comapareIdentifier)
780 higherLimitPosition = comparePosition;
782 else if (resourceType > compareResourceType)
786 else if (resourceType < compareResourceType)
788 higherLimitPosition = comparePosition;
810 if (generatorCount == 0)
813 array<SCR_ResourceGenerator> generators = {};
815 generators.Reserve(generatorCount);
819 generators.Insert(generator);
952 GetGame().GetResourceGrid().FlagResourceItem(
this);
964 GetGame().GetResourceGrid().UnflagResourceItem(
this);
1003 super.OnPostInit(owner);
1005 SetEventMask(owner, EntityEvent.INIT);
1012 set<EResourceType> duplicateRemoveSet =
new set<EResourceType>();
1016 duplicateRemoveSet.Insert(resourceType);
1037 FactionAffiliationComponent factionAffiliationComponentTemp;
1038 IEntity parentEntity = owner.GetParent();
1040 while (parentEntity)
1042 factionAffiliationComponentTemp = FactionAffiliationComponent.Cast(parentEntity.FindComponent(FactionAffiliationComponent));
1044 if (factionAffiliationComponentTemp)
1047 parentEntity = parentEntity.GetParent();
1054 Physics physics = owner.GetPhysics();
1056 vector tempBoundsMaxs, tempBoundsMins;
1066 array<ref SCR_ResourceContainer> containers = prefabData.GetContainers();
1071 typename containerInstanceTypename;
1077 containerInstanceTypename = container.Type();
1082 containerInstance.Initialize(owner, container);
1088 int comparePosition;
1095 compareResourceType = compareContainer.GetResourceType();
1097 if (resourceType > compareResourceType)
1100 else if (resourceType < compareResourceType)
1101 maxPosition = comparePosition;
1110 if (container.IsIsolated())
1113 containerInstance.GetAxisAlignedBoundingVolume(tempBoundsMins, tempBoundsMaxs);
1124 array<ref SCR_ResourceEncapsulator> encapsulators = {};
1129 encapsulator.Initialize(owner);
1132 int maxPosition = encapsulators.Count();
1133 EResourceType resourceType = encapsulator.GetResourceType();
1135 int comparePosition;
1141 compareEncapsulator = encapsulators[comparePosition];
1142 compareResourceType = compareEncapsulator.GetResourceType();
1144 if (resourceType > compareResourceType)
1147 else if (resourceType < compareResourceType)
1148 maxPosition = comparePosition;
1154 encapsulators.InsertAt(encapsulator,
position);
1163 array<ref SCR_ResourceConsumer> consumers = {};
1170 if (container && container.IsEncapsulated())
1173 consumer.Initialize(owner);
1176 int maxPosition = consumers.Count();
1181 int comparePosition;
1182 SCR_ResourceConsumer compareConsumer;
1187 compareConsumer = consumers[comparePosition];
1188 compareGeneratorIdentifier = compareConsumer.GetGeneratorIdentifier();
1189 compareResourceType = compareConsumer.GetResourceType();
1191 if (generatorIdentifier > compareGeneratorIdentifier)
1193 else if (generatorIdentifier < compareGeneratorIdentifier)
1194 maxPosition = comparePosition;
1195 else if (resourceType > compareResourceType)
1197 else if (resourceType < compareResourceType)
1198 maxPosition = comparePosition;
1203 consumers.InsertAt(consumer,
position);
1212 array<ref SCR_ResourceGenerator> generators = {};
1219 if (container && container.IsEncapsulated())
1222 generator.Initialize(owner);
1225 int maxPosition = generators.Count();
1230 int comparePosition;
1236 compareGenerator = generators[comparePosition];
1237 comapareIdentifier = compareGenerator.GetIdentifier();
1238 compareResourceType = compareGenerator.GetResourceType();
1240 if (identifier > comapareIdentifier)
1242 else if (identifier < comapareIdentifier)
1243 maxPosition = comparePosition;
1244 else if (resourceType > compareResourceType)
1246 else if (resourceType < compareResourceType)
1247 maxPosition = comparePosition;
1252 generators.InsertAt(generator,
position);
1261 Vehicle vehicle = Vehicle.Cast(
GetOwner());
1277 SCR_ResourceComponent childResourceComponent = SCR_ResourceComponent.Cast(child.FindComponent(SCR_ResourceComponent));
1278 if (!childResourceComponent)
1287 override event protected void EOnInit(IEntity owner)
1294 queue = encapsulator.GetContainerQueue();;
1296 for (
int i = queue.GetContainerCount() - 1; i >= 0; --i)
1298 container = queue.GetContainerAt(i);
1301 container.GetComponent().SetIsVisible(
false);
1305 bool isCompletelyIsolated =
true;
1310 isCompletelyIsolated &= container.IsIsolated();
1313 if (isCompletelyIsolated)
1320 Vehicle vehicle = Vehicle.Cast(
GetOwner().GetRootParent());
1341 vector origin =
GetOwner().GetOrigin();
1349 consumer.DebugDraw();
1352 height = Math.Max(height, consumer.GetResourceRange());
1362 encapsulator.DebugDraw();
1372 generator.DebugDraw();
1375 height = Math.Max(height, generator.GetStorageRange());
1385 container.DebugDraw();
1395 Shape.CreateArrow((origin + vector.Up * height), origin, 1.0, 0xFFFFFFFF, ShapeFlags.ONCE | ShapeFlags.NOZBUFFER);
1418 Replication.BumpMe();
1431 override event void _WB_AfterWorldUpdate(IEntity owner,
float timeSlice)
1436 super._WB_AfterWorldUpdate(timeSlice);
1441 override event bool _WB_OnKeyChanged(IEntity owner, BaseContainer src,
string key, BaseContainerList ownerContainers, IEntity parent)
1449 consumer.GetContainerQueue().Clear();
1457 generator.GetContainerQueue().Clear();
1461 grid.IncreaseGridUpdateId();
1462 grid.UnregisterResourceItem(
this);
1464 return super._WB_OnKeyChanged(owner, src, key, ownerContainers, parent);
1475 owner.SetFlags(EntityFlags.VISIBLE | EntityFlags.TRACEABLE,
true);
1476 SCR_PhysicsHelper.ChangeSimulationState(owner, SimulationState.COLLISION,
true);
1481 owner.ClearFlags(EntityFlags.VISIBLE | EntityFlags.TRACEABLE,
true);
1505 container.EnableDecay(
false);
1510 bool isCompletelyIsolated =
true;
1514 isCompletelyIsolated &= container.IsEncapsulated();
1517 if (isCompletelyIsolated)
1520 Vehicle vehicle = Vehicle.Cast(
GetOwner().GetRootParent());
1525 GetGame().GetResourceGrid().PromoteResourceItemToDynamic(
this);
1544 container.EnableDecay(
true);
1565 GetGame().GetResourceGrid().PromoteResourceItemToDynamic(
this);
1566 updateSystem.RegisterDynamicComponent(
this);
1571 GetGame().GetResourceGrid().PromoteResourceItemToStatic(
this);
1572 updateSystem.UnregisterDynamicComponent(
this);
1581 ArmaReforgerScripted game =
GetGame();
1591 grid.IncreaseGridUpdateId();
1592 grid.UnregisterResourceItem(
this);
1598 updateSystem.UnregisterDynamicComponent(
this);