Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceContainerItemData.c
Go to the documentation of this file.
1 [BaseContainerProps(configRoot: true), BaseContainerCustomCheckIntTitleField("m_bEnabled", "Resource Container Data", "DISABLED - Resource Container Data", 1)]
3 {
4  [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))]
5  protected EResourceType m_eResourceType;
6 
7  //~ Max Resource Value set by InitData()
8  protected int m_iMaxResourceValue = -1;
9 
10  //--------------------------------- Get resource amount ---------------------------------\\
11 
16  int GetMaxResourceValue()
17  {
18  return m_iMaxResourceValue;
19  }
20 
21  //--------------------------------- Set resource amount ---------------------------------\\
22  //~ Set the resource amount. Done on InitData() taking the info from the ResourceComponent
23  protected void SetMaxResourceValue(int maxResourceValue)
24  {
25  m_iMaxResourceValue = maxResourceValue;
26  }
27 
28  //--------------------------------- Get Resource Container ---------------------------------\\
29  //~ Get container data from SCR_ResourceComponent on Prefab
30  //~ Called on InitData()
31  protected SCR_ResourceContainer GetResourceContainer(notnull SCR_EntityCatalogEntry entry, bool showError = true)
32  {
33  //~ Load Prefab
34  Resource entityPrefab = Resource.Load(entry.GetPrefab());
35  if (!entityPrefab)
36  {
37  if (showError)
38  Debug.Error2("SCR_ResourceContainerItemData", "Data '" + entry.GetPrefab() + "' (index: " + entry.GetCatalogIndex() + ") in catalog '" + typename.EnumToString(EEntityCatalogType, entry.GetCatalogParent().GetCatalogType()) + "' has an invalid prefab!");
39 
40  return null;
41  }
42 
43  //~ Get entity source
44  IEntitySource entitySource = SCR_BaseContainerTools.FindEntitySource(entityPrefab);
45  if (!entitySource)
46  {
47  if (showError)
48  Debug.Error2("SCR_ResourceContainerItemData", "Data '" + entry.GetPrefab() + "' (index: " + entry.GetCatalogIndex() + ") in catalog '" + typename.EnumToString(EEntityCatalogType, entry.GetCatalogParent().GetCatalogType()) + "' has an invalid prefab!");
49 
50  return null;
51  }
52 
53  //~ Get SCR_ResourceComponent on prefab by looping through all components
54  SCR_ResourceContainer resourceContainerTemp;
55  SCR_ResourceContainer resourceContainer;
56  int componentsCount = entitySource.GetComponentCount();
57  for (int i = 0; i < componentsCount; i++)
58  {
59  //~ Check if correct component
60  IEntityComponentSource componentSource = entitySource.GetComponent(i);
61  if (componentSource.GetClassName().ToType().IsInherited(SCR_ResourceComponent))
62  {
63  //~ Grab the resource container BaseContainer
64  BaseContainerList baseContainers = componentSource.GetObjectArray("m_aContainers");
65 
66  if (!baseContainers || baseContainers.Count() == 0)
67  {
68  if (showError)
69  Debug.Error2("SCR_ResourceContainerItemData", "Data '" + entry.GetPrefab() + "' (index: " + entry.GetCatalogIndex() + ") in catalog '" + typename.EnumToString(EEntityCatalogType, entry.GetCatalogParent().GetCatalogType()) + "' has 'SCR_ResourceComponent' but no SCR_ResourceContainer is assigned! (or container variable has been renamed)");
70 
71  return null;
72  }
73 
74  for (int j = baseContainers.Count() - 1; j >= 0; j--)
75  {
76  resourceContainer = SCR_ResourceContainer.Cast(BaseContainerTools.CreateInstanceFromContainer(baseContainers.Get(j)));
77 
78  if (resourceContainer && resourceContainer.GetResourceType() == m_eResourceType)
79  return resourceContainer;
80 
81  }
82  }
83  }
84 
85  if (showError)
86  Debug.Error2("SCR_ResourceContainerItemData", "Data '" + entry.GetPrefab() + "' (index: " + entry.GetCatalogIndex() + ") in catalog '" + typename.EnumToString(EEntityCatalogType, entry.GetCatalogParent().GetCatalogType()) + "' has no 'SCR_ResourceComponent'!");
87 
88  return null;
89  }
90 
91  //--------------------------------- Init Data ---------------------------------\\
92  //~ Set resource amount. Note: Ignored if data is disabled
93  override void InitData(notnull SCR_EntityCatalogEntry entry)
94  {
95  //~ Safty: Already has Init called or invalid
96  if (m_iMaxResourceValue != -1)
97  return;
98 
99  //~ Get resource container and set max resource value
100  SCR_ResourceContainer resourceContainer = GetResourceContainer(entry);
101  if (resourceContainer)
102  SetMaxResourceValue(resourceContainer.GetMaxResourceValue());
103  }
104 };
SCR_BaseEntityCatalogData
Definition: SCR_BaseEntityCatalogData.c:5
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
BaseContainerCustomCheckIntTitleField
Attribute for setting a custom format if the given checkVar is equal to checkVarEqual....
Definition: Attributes.c:659
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
SCR_ResourceContainerItemData
Definition: SCR_ResourceContainerItemData.c:2
SCR_BaseContainerTools
Definition: SCR_BaseContainerTools.c:3
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
SCR_EntityCatalogEntry
Definition: SCR_EntityCatalogEntry.c:5
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468