Exemplo 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);
            }
        }
Exemplo n.º 2
0
 public static void FinaliseConstructionSite(RoadConstructionSite site)
 {
     if (site.GetNextLeg() != null)
     {
         site.GetComponent <WorldObjectComp_ConstructionSite>().SetCosts();
         RoadBuildingState.Caravan.GetComponent <WorldObjectComp_Caravan>().StartWorking();
     }
     else
     {
         RoadConstructionSite.DeleteSite(site);
     }
 }
Exemplo n.º 3
0
        public string progressDescription()
        {
            RoadConstructionSite parentSite    = this.parent as RoadConstructionSite;
            StringBuilder        stringBuilder = new StringBuilder();

            stringBuilder.Append("RoadsOfTheRim_ConstructionSiteDescription_Main".Translate(String.Format("{0:P1}", GetPercentageDone("Work"))));

            // Description of ally's help, if any
            if (parentSite.helpFromFaction != null)
            {
                stringBuilder.Append("RoadsOfTheRim_ConstructionSiteDescription_Help".Translate(parentSite.helpFromFaction.Name, (int)parentSite.helpAmount, String.Format("{0:0.0}", parentSite.helpWorkPerTick)));
                if (parentSite.helpFromTick > Find.TickManager.TicksGame)
                {
                    stringBuilder.Append("RoadsOfTheRim_ConstructionSiteDescription_HelpStartsWhen".Translate(String.Format("{0:0.00}", (float)(parentSite.helpFromTick - Find.TickManager.TicksGame) / (float)GenDate.TicksPerDay)));
                }
            }

            // Show total cost modifiers
            float totalCostModifier = 0f;

            stringBuilder.Append(WorldObjectComp_ConstructionSite.CostModifersDescription(parentSite.Tile, parentSite.GetNextLeg().Tile, ref totalCostModifier));

            List <Caravan> AllCaravansHere = new List <Caravan>();

            Find.WorldObjects.GetPlayerControlledCaravansAt(parentSite.Tile, AllCaravansHere);
            int ISR2G = 0;

            foreach (Caravan c in AllCaravansHere)
            {
                int caravanISR2G = c.GetComponent <WorldObjectComp_Caravan>().useISR2G();
                if (caravanISR2G > ISR2G)
                {
                    ISR2G = caravanISR2G;
                }
            }

            // Per resource : show costs & how much is left to do
            foreach (string resourceName in DefModExtension_RotR_RoadDef.allResourcesAndWork)
            {
                if (GetCost(resourceName) > 0)
                {
                    stringBuilder.AppendLine();
                    string ISR2Gmsg = "";
                    if (ISR2G > 0)
                    {
                        if (resourceName == "Work")
                        {
                            ISR2Gmsg = (ISR2G == 1 ? "RoadsOfTheRim_ConstructionSiteDescription_ISR2Gwork".Translate() : "RoadsOfTheRim_ConstructionSiteDescription_AISR2Gwork".Translate());
                        }
                        else if (DefModExtension_RotR_RoadDef.GetInSituModifier(resourceName, ISR2G))
                        {
                            ISR2Gmsg = (ISR2G == 1 ? "RoadsOfTheRim_ConstructionSiteDescription_ISR2GFree".Translate() : "RoadsOfTheRim_ConstructionSiteDescription_AISR2GFree".Translate());
                        }
                    }
                    stringBuilder.Append("RoadsOfTheRim_ConstructionSiteDescription_Resource".Translate(
                                             resourceName,
                                             String.Format((resourceName == "Work" ? "{0:##.00}" : "{0:##}"), GetLeft(resourceName)), // Only Work should be shown with 2 decimals
                                             (int)GetCost(resourceName),
                                             ISR2Gmsg
                                             ));
                }
            }

            return(stringBuilder.ToString());
        }
Exemplo n.º 4
0
        /*
         * Build the road and move the construction site
         */
        public bool finishWork(Caravan caravan = null)
        {
            RoadConstructionSite parentSite = this.parent as RoadConstructionSite;
            int  fromTile_int = parentSite.Tile;
            int  toTile_int   = parentSite.GetNextLeg().Tile;
            Tile fromTile     = Find.WorldGrid[fromTile_int];
            Tile toTile       = Find.WorldGrid[toTile_int];

            // Remove lesser roads, they don't deserve to live
            if (fromTile.potentialRoads != null)
            {
                foreach (Tile.RoadLink aLink in fromTile.potentialRoads.ToArray())
                {
                    if (aLink.neighbor == toTile_int & RoadsOfTheRim.isRoadBetter(parentSite.roadDef, aLink.road))
                    {
                        fromTile.potentialRoads.Remove(aLink);
                    }
                }
            }
            else
            {
                fromTile.potentialRoads = new List <Tile.RoadLink>();
            }

            if (toTile.potentialRoads != null)
            {
                foreach (Tile.RoadLink aLink in toTile.potentialRoads.ToArray())
                {
                    if (aLink.neighbor == parentSite.Tile & RoadsOfTheRim.isRoadBetter(parentSite.roadDef, aLink.road))
                    {
                        toTile.potentialRoads.Remove(aLink);
                    }
                }
            }
            else
            {
                toTile.potentialRoads = new List <Tile.RoadLink>();
            }

            // Add the road to fromTile & toTile
            fromTile.potentialRoads.Add(new Tile.RoadLink {
                neighbor = toTile_int, road = parentSite.roadDef
            });
            toTile.potentialRoads.Add(new Tile.RoadLink {
                neighbor = fromTile_int, road = parentSite.roadDef
            });
            try
            {
                Find.World.renderer.SetDirty <WorldLayer_Roads>();
                Find.World.renderer.SetDirty <WorldLayer_Paths>();
                Find.WorldPathGrid.RecalculatePerceivedMovementDifficultyAt(fromTile_int);
                Find.WorldPathGrid.RecalculatePerceivedMovementDifficultyAt(toTile_int);
            }
            catch (Exception e)
            {
                RoadsOfTheRim.DebugLog("[RotR] Exception : ", e);
            }

            // The Construction site and the caravan can move to the next leg
            RoadConstructionLeg nextLeg = parentSite.GetNextLeg();

            if (nextLeg != null)
            {
                int CurrentTile = parentSite.Tile;
                parentSite.Tile = nextLeg.Tile;
                RoadConstructionLeg nextNextLeg = nextLeg.Next;
                // TO DO Here : Check if there's an existing road that is the same or better as the one being built. If there is, skip the next leg
                if (nextNextLeg != null)
                {
                    nextNextLeg.Previous = null;
                    setCosts();
                    parentSite.MoveWorkersToNextLeg(CurrentTile); // Move any caravans working on this site to the next leg, and delay faction help if any
                }
                else
                {
                    EndConstruction(caravan);  // We have built the last leg. Notify & remove the site
                }
                Find.World.worldObjects.Remove(nextLeg);
            }

            return(true);
        }