public TieredResource(
     string name,
     string capacityUnits,
     ResearchCategory researchCategory,
     bool canBeStored,
     bool unstoredExcessCanGoToResearch,
     bool isHarvestedLocally,
     TieredResource madeFrom,
     TechTier madeFromStartsAt,
     double effT0, double effT1, double effT2, double effT3, double effT4)
 {
     this.BaseName      = name;
     this.DisplayName   = name;
     this.CapacityUnits = capacityUnits;
     this.CanBeStored   = canBeStored;
     this.ExcessProductionCountsTowardsResearch = unstoredExcessCanGoToResearch;
     this.ResearchCategory        = researchCategory;
     this.IsHarvestedLocally      = isHarvestedLocally;
     this.madeFrom                = madeFrom;
     this.madeFromStartsAt        = madeFromStartsAt;
     this.effectivenessAtTier     = new double[5];
     this.effectivenessAtTier[0]  = effT0;
     this.effectivenessAtTier[1]  = effT1;
     this.effectivenessAtTier[2]  = effT2;
     this.effectivenessAtTier[3]  = effT3;
     this.effectivenessAtTier[4]  = effT4;
     this.reputationPerUnitAtTier = new float[5];
 }
        public static Dictionary <string, TieredResource> LoadAll(Dictionary <string, ResearchCategory> researchCategories)
        {
            ConfigNode[] resourceCategoryNodes         = GameDatabase.Instance.GetConfigNodes("TIERED_RESOURCE_DEFINITION");
            Dictionary <string, TieredResource> result = new Dictionary <string, TieredResource>();

            while (result.Count != resourceCategoryNodes.Length)
            {
                bool madeProgress = false;
                for (int i = 0; i < resourceCategoryNodes.Length; ++i)
                {
                    ConfigNode c = resourceCategoryNodes[i];
                    if (c == null)
                    {
                        continue;
                    }

                    string researchCategory = c.GetValue("research_category");
                    if (researchCategory == null || !researchCategories.TryGetValue(researchCategory, out ResearchCategory category))
                    {
                        Debug.LogError($"TIERED_RESOURCE_DEFINITION.{c.GetValue("name")} misconfigured - missing or invalid research_category");
                        resourceCategoryNodes[i] = null;
                        madeProgress             = true;
                        continue;
                    }

                    string         madeFrom       = c.GetValue("made_from");
                    string         madeFromT2     = c.GetValue("made_from_at_tier2");
                    TieredResource tieredResource = null;
                    TieredResource madeFromResource;
                    if (!string.IsNullOrEmpty(madeFrom) && result.TryGetValue(madeFrom, out madeFromResource))
                    {
                        tieredResource = new TieredResource(c, category, madeFromResource, TechTier.Tier0);
                    }
                    else if (!string.IsNullOrEmpty(madeFromT2) && result.TryGetValue(madeFromT2, out madeFromResource))
                    {
                        tieredResource = new TieredResource(c, category, madeFromResource, TechTier.Tier2);
                    }
                    else if (string.IsNullOrEmpty(madeFrom) && string.IsNullOrEmpty(madeFromT2))
                    {
                        tieredResource = new TieredResource(c, category, null, TechTier.Tier0);
                    }

                    if (tieredResource != null)
                    {
                        result.Add(tieredResource.BaseName, tieredResource);
                        resourceCategoryNodes[i] = null;
                        madeProgress             = true;
                    }
                }

                if (!madeProgress)
                {
                    throw new Exception($"Leftovers {string.Join("|", resourceCategoryNodes.Where(cn => cn != null).Select(cn => cn.GetValue("name")).ToArray())}");
                    //Debug.LogError($"TIERED_RESOURCE_DEFINITION misconfigured - either a made_from or made_from_tier2 attribute is pointing to a non-existant node or there's a circularity.");
                    //break;
                }
            }

            return(result);
        }
 public TieredResource(
     string name,
     string capacityUnits,
     ResearchCategory researchCategory,
     bool canBeStored,
     bool unstoredExcessCanGoToResearch,
     bool isHarvestedLocally,
     TieredResource madeFrom,
     TechTier madeFromStartsAt)
 {
     this.BaseName      = name;
     this.DisplayName   = name;
     this.CapacityUnits = capacityUnits;
     this.CanBeStored   = canBeStored;
     this.ExcessProductionCountsTowardsResearch = unstoredExcessCanGoToResearch;
     this.ResearchCategory        = researchCategory;
     this.IsHarvestedLocally      = isHarvestedLocally;
     this.madeFrom                = madeFrom;
     this.madeFromStartsAt        = madeFromStartsAt;
     this.reputationPerUnitAtTier = name == "Shinies" ? new float[] { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f } : new float[5];
 }