Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GarbageSystem.c
Go to the documentation of this file.
3 {
4  protected const float VEHICLE_RESOURCE_LIFETIME_PERCENTAGE = 0.25;
5 
6  //------------------------------------------------------------------------------------------------
7  override protected float OnInsertRequested(IEntity entity, float lifetime)
8  {
9  // If a vehicle has at least 25% of its supply capacity double the lifetime.
10  if (Vehicle.Cast(entity))
11  {
12  SCR_ResourceContainer container = FindVehicleResourceContainer(entity, EResourceType.SUPPLIES);
13  if (container && (container.GetMaxResourceValue() > 0))
14  {
15  if ((container.GetResourceValue() / container.GetMaxResourceValue()) > VEHICLE_RESOURCE_LIFETIME_PERCENTAGE)
16  {
17  lifetime *= 2;
18  }
19  else // Subscribe for changes that might increase the lifetime later
20  {
21  container.GetOnResourcesChanged().Insert(HandleVehicleResourcesChanged);
22  }
23  }
24  }
25 
26  return lifetime;
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  protected void HandleVehicleResourcesChanged(SCR_ResourceContainer container)
31  {
32  float max = container.GetMaxResourceValue();
33  if ((max > 0) && ((container.GetResourceValue() / max) > VEHICLE_RESOURCE_LIFETIME_PERCENTAGE))
34  {
35  container.GetOnResourcesChanged().Remove(HandleVehicleResourcesChanged);
36  IEntity vehicle = container.GetOwner().GetRootParent();
37  Bump(vehicle, GetLifetime(vehicle));
38  }
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  protected SCR_ResourceContainer FindVehicleResourceContainer(notnull IEntity entity, EResourceType resourceType)
43  {
44  SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
45  if (!resourceComponent)
46  {
47  SlotManagerComponent slotManager = SlotManagerComponent.Cast(entity.FindComponent(SlotManagerComponent));
48  if (!slotManager)
49  return null;
50 
51  EntitySlotInfo slot = slotManager.GetSlotByName("Cargo");
52  if (!slot)
53  return null;
54 
55  entity = slot.GetAttachedEntity();
56  if (!entity)
57  return null;
58 
59  resourceComponent = SCR_ResourceComponent.Cast(entity.FindComponent(SCR_ResourceComponent));
60  }
61 
62  if (!resourceComponent)
63  return null;
64 
65  return resourceComponent.GetContainer(resourceType);
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
70  {
71  ChimeraWorld world = entity.GetWorld();
72  if (!world)
73  return null;
74 
75  return SCR_GarbageSystem.Cast(world.GetGarbageSystem());
76  }
77 }
ChimeraWorld
Definition: ChimeraWorld.c:12
GarbageSystem
Definition: GarbageSystem.c:12
EntitySlotInfo
Adds ability to attach an object to a slot.
Definition: EntitySlotInfo.c:8
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
SCR_GarbageSystem
Script entry for garbage system modding.
Definition: SCR_GarbageSystem.c:2
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34