Esempio n. 1
0
        public void setCosts()
        {
            try
            {
                RoadsOfTheRimSettings settings   = LoadedModManager.GetMod <RoadsOfTheRim>().GetSettings <RoadsOfTheRimSettings>();
                RoadConstructionSite  parentSite = this.parent as RoadConstructionSite;

                float elevationModifier  = 0f;
                float hillinessModifier  = 0f;
                float swampinessModifier = 0f;
                float bridgeModifier     = 0f;
                GetCostsModifiers(parentSite.Tile, parentSite.GetNextLeg().Tile, ref elevationModifier, ref hillinessModifier, ref swampinessModifier, ref bridgeModifier);

                // Total cost modifier
                float totalCostModifier = (1 + elevationModifier + hillinessModifier + swampinessModifier + bridgeModifier) * ((float)settings.BaseEffort / 10);

                DefModExtension_RotR_RoadDef roadDefExtension = parentSite.roadDef.GetModExtension <DefModExtension_RotR_RoadDef>();

                // Check existing roads for potential rebates when upgrading
                GetUpgradeModifiers(parentSite.Tile, parentSite.GetNextLeg().Tile, parentSite.roadDef, out Dictionary <string, int> rebate);

                List <string> s = new List <string>();
                foreach (string resourceName in DefModExtension_RotR_RoadDef.allResourcesAndWork)
                {
                    if (roadDefExtension.GetCost(resourceName) > 0)
                    {
                        int thisRebate = 0;
                        // The cost modifier doesn't affect some advanced resources, as defined in static DefModExtension_RotR_RoadDef.allResourcesWithoutModifiers
                        float costModifierForThisResource = ((DefModExtension_RotR_RoadDef.allResourcesWithoutModifiers.Contains(resourceName)) ? 1 : totalCostModifier);
                        rebate.TryGetValue(resourceName, out thisRebate);
                        // Minimum cost of anything that's needed is 1
                        costs[resourceName] = Math.Max((int)((roadDefExtension.GetCost(resourceName) - thisRebate) * costModifierForThisResource), 1);
                        left[resourceName]  = Math.Max(costs[resourceName], 1f);
                        if (thisRebate > 0)
                        {
                            s.Add("RoadsOfTheRim_UpgradeRebateDetail".Translate((int)(thisRebate * costModifierForThisResource), resourceName));
                        }
                    }
                }

                if (s.Count > 0)
                {
                    Messages.Message("RoadsOfTheRim_UpgradeRebate".Translate(parentSite.roadDef.label, string.Join(", ", s.ToArray())), MessageTypeDefOf.PositiveEvent);
                }

                parentSite.UpdateProgressBarMaterial();
            }
            catch (Exception e)
            {
                Log.Error("[RotR] : Exception when setting constructionSite costs = " + e);
            }
        }
Esempio n. 2
0
        public bool UpdateProgress(float amountOfWork, Caravan caravan = null)
        {
            RoadConstructionSite parentSite = this.parent as RoadConstructionSite;

            ReduceLeft("Work", amountOfWork);

            parentSite.UpdateProgressBarMaterial();

            // Work is done
            if (GetLeft("Work") <= 0)
            {
                return(finishWork(caravan));
            }
            return(false);
        }